home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: c not writing to file
- Date: Thu, 01 Feb 1996 14:47:41 +0200
- Organization: Carelcomp Forest
- Message-ID: <3110B66D.409E@cmt.lpr.mail.carel.fi>
- References: <1996Feb1.115146.24139@river.tay.ac.uk>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Mr persil wrote:
- >
- > this is a sample of my lines of code
- >
- > this should add the variable word to the end of file, but doesn't
- >
- > i used a text editor to create the file
- >
- > text1 = fopen(filename,"a");
- > fprintf (text1,word)
- > fclose (text1)
- >
- > writes something to the hard disk, but nothing appends to the end of
- > the file
- >
- > if i create the file using a c program it appends the word to the
- > end
- >
- > any ideas would be great
- >
- > cheers
- >
- > the mega me
-
- Some editors terminate text files by appending hex 1A (Ctrl+Z) to the end of it. fprintf
- can write past this mark, but TYPE or similar commands don't print what comes after 1A. You
- can check if the file's size changes when you append to it. If this is the case, then you
- can do it like this and have no problems:
-
- 1. open the old file for read (text)
- 2. create new file for write (text)
- 3. read line from the old file
- 4. write the line to the new file
- 5. if still more rows, go to step 3
- 6. add the new stuff to the new file
- 7. close both files
- 8. delete old file
- 9. rename new file to old file's name
-
- HTH,
- AriL
- --
- All my opinions are mine and mine alone.
-